<?php
namespace Admin\Controller;
use Think\Controller;
class FavoriteController extends CommonController {
     public function lists(){
		$favorite = M("favorite");
		$list = $favorite->query("select * from favorite");
		$this->assign("lists",$list);
		if($_REQUEST["name"]){
			$name = $_POST["name"];
			$favorite = M('favorite'); // 实例化User对象
			$numPerPage = empty($_REQUEST["numPerPage"])?2:$_REQUEST["numPerPage"];
			$count  = $favorite->where("name = '$name'")->count();// 查询满足要求的总记录数
			$Page  = new \Think\Page($count,$numPerPage);// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$show  = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list = $favorite->where("name = '$name'")->order("id desc")->limit($Page->firstRow.','.$Page->listRows)->select();
			//当前数据
			$this->assign("lists",$list);
			//总条数
			$this->assign("totalCount",$count);
			//每页显示多少条
			$this->assign("numPerPage",$numPerPage);
			//页标数字多少个
			$this->assign("pageNumShown",$Page->totalPages);
			//当前显示第几页
			$page = empty($_REQUEST["pageNum"])?1:$_REQUEST["pageNum"];
			$this->assign("currentPage",$page);
			$this->assign("name",$name);
		}else{
			$favorite = M('favorite'); // 实例化User对象
			$numPerPage = empty($_REQUEST["numPerPage"])?2:$_REQUEST["numPerPage"];
			$count  = $favorite->count();// 查询满足要求的总记录数
			$Page  = new \Think\Page($count,$numPerPage);// 实例化分页类 传入总记录数和每页显示的记录数(25)
			$show  = $Page->show();// 分页显示输出
			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			$list = $favorite->order("id desc")->limit($Page->firstRow.','.$Page->listRows)->select();
			//当前数据
			$this->assign("lists",$list);
			//总条数
			$this->assign("totalCount",$count);
			//每页显示多少条
			$this->assign("numPerPage",$numPerPage);
			//页标数字多少个
			$this->assign("pageNumShown",$Page->totalPages);
			//当前显示第几页
			$page = empty($_REQUEST["pageNum"])?1:$_REQUEST["pageNum"];
			$this->assign("currentPage",$page);
		}
		$this->display();
	}
}